calamine
An Excel/OpenDocument Spreadsheets file reader/deserializer, in pure Rust.
Description
calamine is a pure Rust library to read and deserialize any spreadsheet file:
- excel like (
xls
,xlsx
,xlsm
,xlsb
,xla
,xlam
) - opendocument spreadsheets (
ods
)
As long as your files are simple enough, this library should just work. For anything else, please file an issue with a failing test or send a pull request!
Examples
Serde deserialization
It is as simple as:
use ;
Note if you want to deserialise a column that may have invalid types (i.e. a float where some values may be strings), you can use Serde's deserialize_with
field attribute:
use ;
use ;
// Convert value cell to Some(f64) if float or int, else None
Reader: Simple
use ;
let mut excel: = open_workbook.unwrap;
if let Some = excel.worksheet_range
Reader: More complex
Let's assume
- the file type (xls, xlsx ...) cannot be known at static time
- we need to get all data from the workbook
- we need to parse the vba
- we need to see the defined names
- and the formula!
use ;
// opens a new workbook
let path = ...; // we do not know the file type
let mut workbook = open_workbook_auto.expect;
// Read whole worksheet data and provide some statistics
if let Some = workbook.worksheet_range
// Check if the workbook has a vba project
if let Some = workbook.vba_project
// You can also get defined names definition (string representation only)
for name in workbook.defined_names
// Now get all formula!
let sheets = workbook.sheet_names.to_owned;
for s in sheets
Features
dates
: Add date related fn toDataType
.
Others
Browse the examples directory.
Performance
While there is no official benchmark yet, my first tests show a significant boost compared to official C# libraries:
- Reading cell values: at least 3 times faster
- Reading vba code: calamine does not read all sheets when opening your workbook, this is not fair
Unsupported
Many (most) part of the specifications are not implemented, the focus has been put on reading cell values and vba code.
The main unsupported items are:
- no support for writing excel files, this is a read-only library
- no support for reading extra contents, such as formatting, excel parameter, encrypted components etc ...
- no support for reading VB for opendocuments
- dates: dates detection is not supported and will return
DataType::Float
. You can use thedates
feature to get friendly conversions fn.
Credits
Thanks to xlsx-js developers! This library is by far the simplest open source implementation I could find and helps making sense out of official documentation.
Thanks also to all the contributors!
License
MIT